<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePaymentsTable extends Migration
{
    /**
     * Run the migrations.
     * 只处理现金支付
     * 如果无需支付现金可以不产生支付记录
     *
     * @return void
     */
    public function up()
    {
        Schema::create('payments', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('order_id')->comment('[v1.0]订单id');

            // 收费信息
            $table->integer('price')->comment('[v1.0]定单需要支付的现金');
            $table->integer('discount_price')->unsigned()->default(0)->comment('[v1.0]优惠金额');
            $table->integer('delivery_fee')->default(0)->comment('应付运费');
            $table->integer('delivery_discount')->default(0)->comment('运费优惠');
            $table->integer('total')->comment('订单实付总金额');

            // 支付
            $table->tinyInteger('channel')->default(0)->comment('[v1.0]支付渠道：0：未知； 1：微信支付；');
            $table->tinyInteger('method')->default(0)->comment('[v1.0]支付方式：0：未发启支付 1：线上支付 2：线下支付；3：积分支付；4：积分+线上支付；5：积分+线下支付；6：会员卡支付');
            $table->integer('pay_cash')->nullable()->comment('[v1.0]支付金额，单位分。在线支付时从支付系统获取，只在支付成功时写入。');
            $table->tinyInteger('status')->default(0)->comment('[v1.0]支付状态 0：未支付 1：支付中 2：支付成功 3：支付失败');
            $table->timestamp('paid_at')->nullable()->comment('[v1.0]支付时间');
            
            $table->timestamps();
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('payments');
    }
}
